from typing import Optional
from fastapi import FastAPI

from client.common import transaction_common
from bsnconfig import contract_name, contract_dir

contract_address = '0xcbf345a4ec7aae2008823858a80c0cc9c9822173'

app = FastAPI()
client = transaction_common.TransactionCommon(
    contract_address, contract_dir, contract_name
)


@app.get('/upload')
def upload(id: str, content: str):
    return client.send_transaction_getReceipt('set', [id, content])


@app.get("/query")
def query(txid: str):
    return client.getTransactionByHash(txid)
